package com.example.logintest01;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Toast;

import com.example.logintest01.bean.MySQLiteOpenHelper;
import com.example.logintest01.bean.Student;
import com.example.logintest01.util.ToastUtil;

public class InsertActivity1 extends AppCompatActivity {

    private EditText etName, etNumber, etClub;
    private RadioButton rbMan, rbWoman;
    private MySQLiteOpenHelper mMySQLiteOpenHelper;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_insert1);

        initView();
        mMySQLiteOpenHelper = new MySQLiteOpenHelper(this);
    }

    private void initView() {
        etName = findViewById(R.id.et_name);
        etNumber = findViewById(R.id.et_number);
        etClub = findViewById(R.id.et_club);
        rbMan = findViewById(R.id.rb_boy);
        rbWoman = findViewById(R.id.rb_girl);

    }

    public void insert(View view) {
        String name = etName.getText().toString().trim();
        String number = etNumber.getText().toString().trim();
        String club = etClub.getText().toString().trim();

        String gender = "";

        if(rbMan.isChecked()){
            gender = "男";
        }
        if(rbWoman.isChecked()){
            gender = "女";
        }

        Student student = new Student();
        student.setName(name);
        student.setNumber(number);
        student.setGender(gender);
        student.setClub(club);



        //插入数据库中

        long rowId = mMySQLiteOpenHelper.insertData(student);
        if(rowId != -1){
            ToastUtil.toastShort(this,"添加成功！" );
        }else{
            ToastUtil.toastShort(this,"添加失败！" );
        }

    }
}